package cn.wolfcode.luowowo.mgrsite.controller;

import cn.wolfcode.luowowo.article.domain.Answer;
import cn.wolfcode.luowowo.article.query.AnswerQuery;
import cn.wolfcode.luowowo.article.service.IAnswerService;
import cn.wolfcode.luowowo.common.util.AjaxResult;
import com.alibaba.dubbo.config.annotation.Reference;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/answer")
public class AnswerController {

    @Reference
    private IAnswerService answerService;

    // 查询回答列表
    @RequestMapping("/list")
    public String list(Model model, @ModelAttribute("qo") AnswerQuery qo) {
        model.addAttribute("pageInfo", answerService.query(qo));
        return "/community/Answerlist";
    }
    @RequestMapping("/getContent")
    @ResponseBody
    public AjaxResult getContent(  Long id) {
        AjaxResult result = new AjaxResult();
        Answer answer = answerService.getContent(id);
        result.setData(answer.getContent());
        return result;
    }
    @RequestMapping("/upByStatus")
    @ResponseBody
    public AjaxResult upByStatus(  Answer answer) {
        AjaxResult result = new AjaxResult();
        try {
            answerService.upByStatus(answer);
        }catch (Exception e){
            result.setSuccess(false);
            result.setMsg(e.getMessage());
        }
        return result;
    }

}
